<?php

namespace Modules\Admin\Http\Controllers;

use HiCommon\Service\AccountSettleService;
use Illuminate\Support\Facades\Request;

class AccountSettleController extends BaseController
{

    /****************************************** 订单结算 ******************************************/
    /*订单结算列表*/
    public function index(){
        try {

            $arr_input = Request::input();
            $result = AccountSettleService::get_all_list_for_admin($arr_input);
            $arr_data = $result['data'];
//            dd($arr_data);
            echo_error($result);
            return view('admin::account_settle.index', $arr_data);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*订单结算-驳回结算操作*/
    public function refuse_settle(){
        try {
            $arr_input = Request::input();

            //提交
            shiwu_start();
            $result = AccountSettleService::api_refuse_settle($arr_input);
            shiwu_end($result);

            return  $result;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*订单结算-确认结算页面*/
    public function confirm_page(){
        try {
            $n_id = intval(Request::input('id',0));
            $result = AccountSettleService::api_find_one($n_id);
            echo_error($result);
            $arr_data = [
              'arr_data'=>$result['data'],
              'arr_account_type'=>[
                'ali'=>'支付宝',
                'bank'=>'银行卡',
              ],
            ];

            return view('admin::account_settle.confirm_page',$arr_data);
        }
        catch (\Exception $exception) {
            msg_error('fail-'.$exception->getMessage());
            return 'ok';
        }
    }

    /*订单结算-确认结算操作*/
    public function confirm(){
        try {
            $arr_input = Request::input();

            //修改
            shiwu_start();
            $arr_input['state'] = 3;
            $arr_input['settle_time'] = time_to_ymdhis();
            $result = AccountSettleService::api_shop_edit_one($arr_input);
            shiwu_end($result);

            return  $result;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /****************************************** 优惠券津贴结算 ******************************************/

    /*优惠券津贴结算列表*/
    public function coupon_index(){
        try {

            $arr_input = Request::input();
            $result = AccountSettleService::get_settle_coupon_list_for_admin($arr_input);
            $arr_data = $result['data'];
            //            dd($arr_data);
            echo_error($result);
            return view('admin::account_settle.coupon_index', $arr_data);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*优惠券津贴结算-驳回结算操作*/
    public function coupon_refuse_settle(){
        try {
            $arr_input = Request::input();

            //提交
            shiwu_start();
            $result = AccountSettleService::api_refuse_settle($arr_input);
            shiwu_end($result);

            return  $result;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*优惠券津贴结算-确认结算页面*/
    public function coupon_confirm_page(){
        try {
            $n_id = intval(Request::input('id',0));
            $result = AccountSettleService::api_find_one($n_id);
            echo_error($result);
            $arr_data = [
              'arr_data'=>$result['data'],
              'arr_account_type'=>[
                'ali'=>'支付宝',
                'bank'=>'银行卡',
              ],
            ];

            return view('admin::account_settle.coupon_confirm_page',$arr_data);
        }
        catch (\Exception $exception) {
            msg_error('fail-'.$exception->getMessage());
            return 'ok';
        }
    }

    /*优惠券津贴结算-确认结算操作*/
    public function coupon_confirm(){
        try {
            $arr_input = Request::input();

            //修改
            shiwu_start();
            $arr_input['state'] = 3;
            $arr_input['settle_time'] = time_to_ymdhis();
            $result = AccountSettleService::api_shop_edit_one($arr_input);
            shiwu_end($result);

            return  $result;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

}
